﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Title="用户举报的视频" %>

<script runat="server">

	protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
	{
		ListDictionary keyValues = new ListDictionary();
		ListDictionary newValues = new ListDictionary();
		ListDictionary oldValues = new ListDictionary();
		
		if (e.CommandName == "DeleteIt")
		{
			keyValues.Add("Id", int.Parse(e.CommandArgument.ToString()));
			newValues.Add("IsDeleted", true);
			LinqDataSource1.Update(keyValues, newValues, oldValues);

			ListView1.DataBind();
		}
		else if (e.CommandName == "ClearReport")
		{
			keyValues.Add("Id", int.Parse(e.CommandArgument.ToString()));
			newValues.Add("ReportNumber", 0);
			LinqDataSource1.Update(keyValues, newValues, oldValues);

			ListView1.DataBind();
		}
		else if (e.CommandName == "BlockIP")
		{
			int id = int.Parse(e.CommandArgument.ToString());
			string ip = null;
			
			using (TDataContext db = new TDataContext())
			{
				var comment = db.TComments.First(c => c.Id == id);
				ip = comment.UserIp;
			}

			TIpUtility.Block(ip, false);
			ListView1.DataBind();
		}
	}
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
	<asp:LinqDataSource ID="LinqDataSource1" runat="server" 
		ContextTypeName="Xpus.YouYTube.Data.TDataContext" EnableUpdate="True" 
		OrderBy="ReportNumber desc" TableName="TComments" 
		Where="ReportNumber &gt; 0 &amp;&amp; IsDeleted == false">
	</asp:LinqDataSource>
	<asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
		DataSourceID="LinqDataSource1" onitemcommand="ListView1_ItemCommand">
		<LayoutTemplate>
			<div ID="itemPlaceholderContainer" runat="server" style="">
				<div ID="itemPlaceholder" runat="server" />
			</div>
			<div style="">
				<asp:DataPager ID="DataPager1" runat="server">
					<Fields>
						<asp:NextPreviousPagerField ShowFirstPageButton="True" 
							ShowNextPageButton="False" FirstPageText="第一页" PreviousPageText="上一页" />
						<asp:NumericPagerField ButtonCount="20" />
						<asp:NextPreviousPagerField ShowLastPageButton="True" 
							ShowPreviousPageButton="False" LastPageText="最后一页" NextPageText="下一页" />
					</Fields>
				</asp:DataPager>
			</div>
		</LayoutTemplate>
		<EmptyDataTemplate>
			<span>暂无数据。</span>
		</EmptyDataTemplate>
		<ItemTemplate>
			<p>[举报数：<%# Eval("ReportNumber") %>] #<%# Eval("Id") %> [<%# HttpUtility.HtmlEncode(Eval("UserName").ToString()) %>] <%# ((DateTime)Eval("AddedTime")).ToString("yyyy-MM-dd HH:mm:ss") %></p>
			<p><%# HttpUtility.HtmlEncode(Eval("Body").ToString()) %></p>
			<p>IP: <%# Eval("UserIp") %>
			<%# TIpUtility.IsIpBlocked(Eval("UserIp").ToString(), false) ? "已屏蔽" : "" %>
			<asp:LinkButton runat="server" CommandName="BlockIP" CommandArgument='<%# Eval("Id") %>' Text="屏蔽该IP"></asp:LinkButton>
			</p>
			<p><asp:LinkButton runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="DeleteIt" Text="删除该评论"></asp:LinkButton>
			<asp:LinkButton runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="ClearReport" Text="将举报数清零"></asp:LinkButton></p>
		</ItemTemplate>
		<ItemSeparatorTemplate><hr /></ItemSeparatorTemplate>
	</asp:ListView>
</asp:Content>

